<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>APP</title>
    <link rel="stylesheet" href="../css/api.css" />
    <link rel="stylesheet" href="../css/aui.css" />
    <link rel="stylesheet" href="../css/aui-flex.css" />
    <link rel="stylesheet" href="../css/common.css" />
    <link rel="stylesheet" href="../css/login.css">
    <link rel="stylesheet" href="../css/font/iconfont.css">
</head>
<body>
    <div id="wrap">
      <header class="aui-bar aui-bar-nav aui-bg-danger">
        <div class="aui-pull-left aui-btn" onclick="closeWin();">
          <span class="aui-iconfont aui-icon-left"></span>
        </div>
        <div class="aui-title aui-text-white">找回密码</div>
      </header>
        <div>
          <div class="aui-flex-col aui-flex-middle aui-padded-10 aui-bg-white aui-margin-t-10">
            <label class="aui-margin-r-10">手机号</label>
            <div class="aui-flex-auto aui-list-item-input">
              <input
                id="oldTele"
                class="aui-font-size-14"
                type="tele"
                placeholder="请输入手机号"
              >
            </div>
          </div>

          <div class="aui-padded-l-10 aui-padded-r-10 aui-bg-white">
            <div class="aui-flex-col aui-flex-middle  aui-margin-t-10" style="position: relative;">
              <label class="aui-margin-r-10">验证码</label>
              <div class="aui-flex-auto aui-list-item-input">
                <input
                  id="code"
                  class="aui-font-size-14"
                  type="text"
                  placeholder="请输入短信验证码"
                >
              </div>
              <span class="aui-font-size-12 aui-btn aui-bg-danger aui-text-white tele-code-btn" onclick="getPwdCode()">获取验证码</span>
            </div>
            <div class="aui-hr"></div>
            <p class="aui-font-size-12 aui-padded-t-10 aui-padded-b-10">
              点击获取验证码您可收到验证短信，五分钟内有效
            </p>
          </div>

          <div class="aui-flex-col aui-flex-middle aui-padded-l-10 aui-padded-r-10 aui-bg-white aui-margin-t-10">
            <label class="aui-margin-r-10">密码</label>
            <div class="aui-flex-auto aui-list-item-input">
              <input
                id="pwd1"
                class="aui-font-size-14"
                type="text"
                placeholder="请输入密码"
              >
            </div>
          </div>

          <div class="aui-flex-col aui-flex-middle aui-padded-l-10 aui-padded-r-10 aui-bg-white aui-margin-t-10">
            <label class="aui-margin-r-10">确认密码</label>
            <div class="aui-flex-auto aui-list-item-input">
              <input
                id="pwd2"
                class="aui-font-size-14"
                type="text"
                placeholder="请再次输入密码"
              >
            </div>
          </div>

          <div class="aui-padded-15 aui-margin-t-25">
            <div
              class="aui-btn aui-btn-block aui-bg-danger aui-text-white"
              onclick="resetPwd()"
            >确定</div>
          </div>

          <div class="aui-padded-10 aui-text-center aui-text-grey-dark" onclick="openWin('login')">
            已有帐号登录
          </div>
        </div>
    </div>
</body>
<script src="../script/api.js"></script>
<script src="../script/zepto.js"></script>
<script src="../script/common.js"></script>
<script>
    var count = 0; //间隔函数，1秒执行
    var InterValObj; //timer变量，控制时间
    var icode = '';

    function resetPwd(){
        if ($('#tele').val() == '') {
            alert('请输入手机号');
            return;
        }
        if ($('#pwd1').val() == '') {
            alert('请输入密码');
            return;
        }
        if ($('#pwd1').val() != $('#pwd2').val()) {
            alert('密码验证不一致');
            return;
        }
        if ($('#code').val() == '') {
            alert('请输入手机验证码');
            return;
        }
        var d = {
            pwd: $('#pwd1').val(),
            code: $('#code').val()
        }

        $.ajax({
            url : "http://www.aiyi5.com/doForgetPwd",
            type : "POST",
            data : d,
            async : false,
            dataType: 'json',
            error : function(errorMsg) {

            },
            success : function(data) {
                alert(data.msg);
                if(data.code == '0'){
                    window.location.href = 'login.html';
                }
            }
        });
    }

    function getPwdCode() {
        if(count > 0){
            return;
        }
        var tele = $('#tele').val();
        if (!(tele.length == 11 && /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|)+\d{8})$/
                .test(tele))) {
            alert('请输入正确的手机号');
            return;
        }

        var d = {
            tele : tele
        }

        $.ajax({
            url : "http://www.aiyi5.com/getPwdCode",
            type : "POST",
            data : d,
            async : false,
            dataType: 'json',
            error : function(errorMsg) {

            },
            success : function(data) {
                count = 60;
                if (data.code == '0') {
                    $("#smsCode").val(count + "秒");
                    InterValObj = window.setInterval(SetRemainTime, 1000);
                } else {
                    alert('发送失败');
                }
            }
        });
    }

    function SetRemainTime() {
        if (count == 0) {
            window.clearInterval(InterValObj);//停止计时器
            $("#smsCode").val("获取验证码");
        } else {
            count--;
            $("#smsCode").val(count + "秒");
        }
    }
</script>
</html>
